package ioc;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class PersonTest {
	@Test
	public void instanceSpring1() {
		/**
		 * 
		 * spring 的实现
		 */
		// IOC
		ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
		PersonDAO pd = (PersonDAO) ac.getBean("personDAO");
		pd.save();
		// DI
		PersonService ps = (PersonService) ac.getBean("personService");
		ps.save();
	}

	@Test
	public void instanceSpring2() {

		/**
		 * 我的实现
		 * 
		 */
		MyClassPathXmlApplicationContext mac = new MyClassPathXmlApplicationContext("beans.xml");
		PersonDAO mpd = (PersonDAO) mac.getBean("personDAO");
		mpd.save();
		// DI
		PersonService ps = (PersonService) mac.getBean("personService");
	}

}